package framework.view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import framework.controller.Controller;
import framework.controller.GameController;
import framework.model.GameModel;
import framework.model.Model;

public class ForfeitView extends InteractiveView {

	private JButton forfeitButton;
	
	public ForfeitView(GameModel model, GameController controller) {
		super(model, controller);
		init();
		this.getModel().addListener(this);
		add(forfeitButton);
		forfeitButton.addActionListener(this);
	}

	private void init() {
		// Panel
		setLayout(new GridLayout());
		// Button
		forfeitButton = new JButton("FORFEIT");
		forfeitButton.setBackground(Color.RED);
		forfeitButton.setForeground(Color.WHITE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource() == forfeitButton){
			int q = JOptionPane.showConfirmDialog(
				    null,
				    "Are you sure you want to give up the game and admit you are a failure?",
				    "Accept defeat",
				    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
			if(q == 0){
				this.getController().handleForfeitRequest();
			}
		}
	};

	@Override
	public GameController getController() {
		return (GameController)super.getController();
	};
}
